<script setup>
  import { ref, onMounted } from 'vue'
  import { useRouter } from 'vue-router'
  import PageHeader from "@/components/PageHeader.vue";
  import { GiftOutlined } from '@ant-design/icons-vue'
  import { getGiftListApi } from "@/api/index.js";
  const router = useRouter()
  const giftList = ref([])
  const goDetail = (info) => {
    router.push(`goods?spu=${info.spu}&type=gift`)
  }
  const nav = (name) => {
    router.push({name})
  }
  onMounted(() => {
    getGiftListApi({ filter: {available: 1}}).then(res => {
      giftList.value = res.data
    })
  })
</script>

<template>
  <div class="gift-page">
    <PageHeader>
      <GiftOutlined style="font-size: 18px;cursor: pointer" @click="nav('giftOrderList')"/>
    </PageHeader>
    <div class="goods-list">
      <div class="goods-item" v-for="(info, index) in giftList" :key="index">
        <div class="goods-img">
          <img :src="info?.img" alt="" class="goods-thumb">
          <div class="tag-list" v-if="info?.label_arr?.length">
            <a-tag :bordered="false" v-for="tag in info?.label_arr" :key="tag"> {{ tag }} </a-tag>
          </div>
        </div>
        <div class="goods-info">
          <div class="goods-name"> {{ info?.name }} </div>
          <div class="goods-price-mark">
            <div class="goods-price">
              <div class="new-p"> {{ info?.gift_price }} </div>
            </div>
            <div class="goods-mark"> 评分 {{ info?.score }} </div>
          </div>
          <a-button type="primary" style="background: var(--primary)" @click="goDetail(info)"> 查看详情 </a-button>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
  .gift-page {
    padding-top: 40px;
    .goods-list {
      .goods-item {
        width: 100%;
        max-width: 300px;
        overflow: hidden;
        border-radius: 15px;
        background-color: #fff;
        .goods-img {
          width: 100%;
          padding-bottom: 140%;
          position: relative;
          .goods-thumb {
            position: absolute;
            width: 100%;
            height: 100%;
          }
          .tag-list {
            position: absolute;
            right: 0;
            bottom: 10px;
            display: flex;
            flex-direction: column;
            gap: 10px;
          }
        }
        .goods-info {
          width: 100%;
          gap: 5px;
          display: flex;
          flex-direction: column;
          padding: 10px 12px;
          .goods-name {
            width: 100%;
            font-weight: bold;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
          .goods-price-mark {
            color: #999;
            font-size: 12px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            .goods-price {
              display: flex;
              font-weight: bold;
              align-items: end;
              .new-p {
                color: red;
                font-size: 16px;
                line-height: 16px;
              }
              .old-p {
                line-height: 12px;
                margin-left: 5px;
                text-decoration: line-through;
              }
            }
            .goods-mark {
              color: red;
            }
          }
          .ant-btn {
            width: 100%;
            margin-top: 10px;
          }
        }
      }
    }
  }
</style>